Ad Widget

Collapse

Probleme de connexion à zabbix à travers JSONRPC

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marwaIF
    Junior Member
    • Mar 2013
    • 6

    #1

    Probleme de connexion à zabbix à travers JSONRPC

    Bonjour tout le monde,
    je veux utiliser le service web de Zabbix et je developpe un simple code pour s'authentifier
    Code:
    import com.thetransactioncompany.jsonrpc2.client.*;
    
    	// The Base package for representing JSON-RPC 2.0 messages
    	import com.thetransactioncompany.jsonrpc2.*;
    
    	// The JSON Smart package for JSON encoding/decoding (optional)
    	import net.minidev.json.*;
    
    	// For creating URLs
    import java.net.*;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    
    
    	public class Exemple {
    
    
    		public static void main(String[] args) {
    
    
    			// Creating a new session to a JSON-RPC 2.0 web service at a specified URL
    
    			// The JSON-RPC 2.0 server URL
    			URL serverURL = null;
    
    			try {
    				serverURL = new URL("http://Zabbix_server/zabbix/api_jsonrpc.php");
    
    			} catch (MalformedURLException e) {
    			// handle exception...
    			}
    
    			// Create new JSON-RPC 2.0 client session
    			JSONRPC2Session mySession = new JSONRPC2Session(serverURL);
    
    
    			// Once the client session object is created, you can use to send a series
    			// of JSON-RPC 2.0 requests and notifications to it.
    
    			// Sending an example "getServerTime" request:
    
    			// Construct new request
    			String method = "user.authenticate";
    			Map<String,String> params = new HashMap<String,String>();
    			params.put("user", "password");
    			params.put("admin", "zabbix");
    			int requestID =2 ;
    			JSONRPC2Request request = new JSONRPC2Request(method, requestID);
    
    			// Send request
    			JSONRPC2Response response = null;
    
    			try {
    				response = mySession.send(request);
    
    			} catch (JSONRPC2SessionException e) {
    
    			System.err.println(e.getMessage());
    			// handle exception...
    			}
    
    			// Print response result / error
    			if (response.indicatesSuccess())
    				System.out.println(response.getResult());
    			else
    				System.out.println(response.getError().getMessage());
    		
    		}
    	}
    je reçois un exception :Network exception: Connection timed out: connect
    Ce quoi le probléme aider moi SVP?
  • JBo
    Senior Member
    • Jan 2011
    • 310

    #2
    Bonjour,

    Originally posted by marwaIF
    je reçois un exception :Network exception: Connection timed out: connect
    Ce quoi le probléme aider moi SVP?
    La réponse est dans la question, non ?
    As-tu vérifié que l'URL http://Zabbix_server/zabbix/api_jsonrpc.php est valide ?
    Que se passe-t-il si tu accèdes à cette adresse depuis la barre d'adresse d'un navigateur ?

    Cordialement,
    JBo

    Comment

    • marwaIF
      Junior Member
      • Mar 2013
      • 6

      #3
      Unexpected &quot;text/html&quot; content type of the HTTP response

      Merci JBo pour ton réponse ,
      je verfie mon url et je resoudre cette probléme,mais maintenant j'ai une autre exception pour la méme code Unexpected "text/html" content type of the HTTP response
      avez vous une idée sur la cause de probléme?

      Comment

      Working...